let app = getApp();
const WXAPI = require('../../utils/main')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    allOrderList: [], //所有
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    that.allOrdersPsot()
  },
  //订单接口
  allOrdersPsot:function(){
    let that = this
    that.selectComponent("#loading").show();
    WXAPI.commodity_order({  
      _uid:wx.getStorageSync('uid'),
      _do:'refund',
      _refund:1
    }).then(function (res) {
        that.selectComponent("#loading").hide()
        console.log(res)
        that.setData({
            allOrderList:res,
            database: true
        })
    }).catch(function (e) {
      wx.hideLoading()
      console.log(e)
    })
  },

  orderStatusBtn:function(e){
    let that = this
    let textType = +e.currentTarget.dataset.type; //状态  6:查看进度 7：取消申请
    let orderNmberId = +e.currentTarget.dataset.id; // 订单的id

    if (textType == 6){

    }else if(textType == 7){
      wx.showModal({
        title: '是否取消申请',
        showCancel: true,
        cancelText: '取消',
        cancelColor: '#000000',
        confirmText: '确定',
        confirmColor: '#3CC51F',
        success: async(result) => {
            if (result.confirm) {
              WXAPI.commodity_order({  
                _uid:wx.getStorageSync('uid'),
                _do:'edit',
                _id:orderNmberId
              }).then(function (res) {
                  console.log(res)
                  if (res.res == 1) {
                    wx.showToast({
                       title: "取消申请成功",
                       icon: "none",
                    });
                   that.onPullDownRefresh()
                  } else{
                      wx.showToast({
                          title: "message",
                          icon: "none",
                      });
                  }
              }).catch(function (e) {
                wx.hideLoading()
                console.log(e)
              })
            }
        },
      });
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.selectComponent("#loading").show();
    this.setData({
        allOrderList: []
    })
    // this.setData({
    //     page: 0,
    //     identifier: true
    // })
    setTimeout(() => {　　　　　　　　
        this.allOrdersPsot();　
        wx.stopPullDownRefresh(); //停止下拉刷新
    }, 1000);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})